﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSModel;
using TTSBLL;
using TTS;
public partial class Repair_DM_DM_T0002052 : System.Web.UI.Page
{
   private Assemble assemble_T0002040;
    private AssembleItem assembleItem_T0002040;
    private string message;
    private string sn { get { return ViewState["sn"].ToString(); } set { ViewState["sn"] = value; } }
    private const string storedProcedureName = "DMT0002052_Delete";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.T0002052_inputSN.Focus();
    }

    public Repair_DM_DM_T0002052()
    {
        assemble_T0002040 = new Assemble();
        assembleItem_T0002040 = new AssembleItem();
    }
    protected void T0002052_inputSN_TextChanged(object sender, EventArgs e)
    {
        sn = this.T0002052_inputSN.Text.Trim();
        if (SNHelper.SNCheck(sn, "T0002052", out message))
        {
            if (!assembleItem_T0002040.AssembleItem_SubSNAlreadyExist(sn))
            {
                if (assemble_T0002040.Assemble_SNAlreadyExist(sn))
                {                   
                        this.Repair.Enabled = true;
                        this.Repair.Focus();                   
                }
                else
                {
                    message = "该" + sn + "在数据库中不存在装配记录，请重新扫描正确的SN号！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                    this.T0002052_inputSN.Text = "";
                }
            }
            else
            {
                message = "请先选择T0002368机箱组件进行解锁！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                this.T0002052_inputSN.Text = "";
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        }
    }
    protected void Repair_Click(object sender, EventArgs e)
    {
        assemble_T0002040.AssembleDeleteBySN(sn, storedProcedureName);
        message = "装配关系解锁成功！";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.T0002052_inputSN.Text = "";
        this.Repair.Enabled = false;
    }
    protected void Return_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Repair/DM/DMRepairHtml.aspx");
    }
   
}